import unittest
from 回溯算法alg import is_palindrome

class TestIsPalindrome(unittest.TestCase):
    def test_valid_palindrome(self):
        self.assertTrue(is_palindrome("A man, a plan, a canal: Panama"))
        self.assertTrue(is_palindrome("racecar"))
        self.assertTrue(is_palindrome("No lemon, no melon"))
        self.assertTrue(is_palindrome("A man, a plan, a 13 canal: Panama13"))
    
    def test_invalid_palindrome(self):
        self.assertFalse(is_palindrome("race a car"))
        self.assertFalse(is_palindrome("hello"))
        self.assertFalse(is_palindrome("not a palindrome"))
    
    def test_edge_cases(self):
        self.assertTrue(is_palindrome(""))  # 空字符串
        self.assertTrue(is_palindrome("a"))  # 单字符
        self.assertTrue(is_palindrome(" "))  # 全空格
        self.assertTrue(is_palindrome("!@#$%^&*()"))  # 无字母数字
        self.assertFalse(is_palindrome("ab"))  # 两个不同字符
    
    def test_case_insensitive(self):
        self.assertTrue(is_palindrome("Madam"))
        self.assertTrue(is_palindrome("Was it a car or a cat I saw"))
    
    def test_performance(self):
        # 测试大字符串性能
        large_valid = 'a' * 100000 + ' ' + 'a' * 100000
        self.assertTrue(is_palindrome(large_valid))
        
        large_invalid = 'a' * 100000 + 'b' + 'a' * 99999
        self.assertFalse(is_palindrome(large_invalid))

if __name__ == '__main__':
    unittest.main()    